function addService()
{
    $.ajax({
        type : 'post',
        dataType : 'json',
        url : $("#website").val()+'sys/backend_promote/addpingservice/',
        data : {service : $("#add-service").val()},
        success : function (response) {
            if (response.id > 0) {
                $("#add-service").val('http://');
                $("#form-add-service-id").val(0);
                $(".pingbloglist").html($(".pingbloglist").html()+response.content);
                $(".success").html("Added.");
                $(".success").show();
            }
        }
    });
}

function updateService()
{
    $.ajax({
        type : 'post',
        dataType : 'json',
        url : $("#website").val()+'sys/backend_promote/updateservice/',
        data : {id : $("#form-add-service-id").val(), service : $("#add-service").val()},
        success : function (response) {
            if (response.update) {
                var id = $("#form-add-service-id").val();
                var serviceURL = response.service;
                $("#service-"+id).find(".service-url span").attr("title", serviceURL);
                $("#service-"+id).find(".service-url span").html(serviceURL.length < 50 ? serviceURL : serviceURL.substr(0, 50)+'...');
                $("#add-service").val('http://');
                $(".formsubmit").html('Add');
                $("#form-add-service-id").val(0);
                $(".success").html("Updated.");
                $(".success").show();
            }
        }
    });
}

function editService(id)
{
    if (/^([0-9]{1,10})$/.test(id) && id > 0) {
        $("#add-service").val($("#service-"+id).find(".service-url span").attr("title"));
        $(".formsubmit").html('Edit');
        $("#form-add-service-id").val(id);
    }
}

function deleteSevice(id)
{
    if (/^([0-9]{1,10})$/.test(id) && id > 0) {
        $.ajax({
            type : 'post',
            dataType : 'json',
            url : $("#website").val()+'sys/backend_promote/deleteservice/',
            data : {id : id},
            success : function (response) {
                if (response.del) {
                    $("#service-"+id).css("background-color","#FFFF00");
                    $("#service-"+id).fadeOut(300, function() {
                        var elm = document.getElementById("service-"+id);
                        elm.parentNode.removeChild(elm);
                    });
                }
            }
        });
    }
}